<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位水平垂直居中</title>
    <style>
        body {
            height: 1200px;
        }
        /* .box {
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: skyblue;
            margin: auto auto;
            left: 0%;
            right: 0%;
            top: 0px;
            bottom: 0px;
        } */
        .box {
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: skyblue;
            /* 1.left走50% 为父容器宽度的一半 */
            left: 50%;
            /* 2.margin-left设为负值，往左边走自己盒子宽度的一半 */
            margin-left: -100px;

            /* 1.top走50% 为父容器高度的一半 */
            top: 50%;
            /* 2.margin-top设为负值，往上边走自己盒子高度的一半 */
            margin-top: -100px;
        } 
       
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>